<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActionView::Helpers::RecordTagHelper</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            ActionView::Helpers::RecordTagHelper 
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/actionpack/lib/action_view/helpers/record_tag_helper_rb.html">actionpack/lib/action_view/helpers/record_tag_helper.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>C</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="RecordTagHelper.html#method-i-content_tag_for">content_tag_for</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>D</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="RecordTagHelper.html#method-i-div_for">div_for</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  
    <!-- Includes -->
    <div class="sectiontitle">Included Modules</div>
    <ul>
      
        <li>
          
            <a href="../RecordIdentifier.html">
              ActionView::RecordIdentifier
            </a>
          
        </li>
      
    </ul>
  



  

    

    

    


    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-content_tag_for">
            
              <b>content_tag_for</b>(tag_name, single_or_multiple_records, prefix = nil, options = nil, &amp;block)
            
            <a href="RecordTagHelper.html#method-i-content_tag_for" name="method-i-content_tag_for" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p><a
href="RecordTagHelper.html#method-i-content_tag_for">#content_tag_for</a>
creates an <a href="../../HTML.html">HTML</a> element with id and class
parameters that relate to the specified Active Record object. For example:</p>

<pre>&lt;%= content_tag_for(:tr, @person) do %&gt;
  &lt;td&gt;&lt;%= @person.first_name %&gt;&lt;/td&gt;
  &lt;td&gt;&lt;%= @person.last_name %&gt;&lt;/td&gt;
&lt;% end %&gt;</pre>

<p>would produce the following <a href="../../HTML.html">HTML</a> (assuming
@person is an instance of a Person object, with an id value of 123):</p>

<pre class="ruby"><span class="ruby-operator">&lt;</span><span class="ruby-identifier">tr</span> <span class="ruby-identifier">id</span>=<span class="ruby-string">&quot;person_123&quot;</span> <span class="ruby-identifier">class</span>=<span class="ruby-string">&quot;person&quot;</span><span class="ruby-operator">&gt;</span><span class="ruby-operator">...</span>.<span class="ruby-operator">&lt;</span><span class="ruby-operator">/</span><span class="ruby-identifier">tr</span><span class="ruby-operator">&gt;</span>
</pre>

<p>If you require the <a href="../../HTML.html">HTML</a> id attribute to have
a prefix, you can specify it:</p>

<pre>&lt;%= content_tag_for(:tr, @person, :foo) do %&gt; ...</pre>

<p>produces:</p>

<pre class="ruby"><span class="ruby-operator">&lt;</span><span class="ruby-identifier">tr</span> <span class="ruby-identifier">id</span>=<span class="ruby-string">&quot;foo_person_123&quot;</span> <span class="ruby-identifier">class</span>=<span class="ruby-string">&quot;person&quot;</span><span class="ruby-operator">&gt;</span><span class="ruby-operator">...</span>
</pre>

<p>You can also pass an array of objects which this method will loop through
and yield the current object to the supplied block, reducing the need for
having to iterate through the object (using <code>each</code>) beforehand.
For example (assuming @people is an array of Person objects):</p>

<pre>&lt;%= content_tag_for(:tr, @people) do |person| %&gt;
  &lt;td&gt;&lt;%= person.first_name %&gt;&lt;/td&gt;
  &lt;td&gt;&lt;%= person.last_name %&gt;&lt;/td&gt;
&lt;% end %&gt;</pre>

<p>produces:</p>

<pre class="ruby"><span class="ruby-operator">&lt;</span><span class="ruby-identifier">tr</span> <span class="ruby-identifier">id</span>=<span class="ruby-string">&quot;person_123&quot;</span> <span class="ruby-identifier">class</span>=<span class="ruby-string">&quot;person&quot;</span><span class="ruby-operator">&gt;</span><span class="ruby-operator">...</span><span class="ruby-operator">&lt;</span><span class="ruby-regexp">/tr&gt;
&lt;tr id=&quot;person_124&quot; class=&quot;person&quot;&gt;...&lt;/</span><span class="ruby-identifier">tr</span><span class="ruby-operator">&gt;</span>
</pre>

<p><a
href="RecordTagHelper.html#method-i-content_tag_for">#content_tag_for</a>
also accepts a hash of options, which will be converted to additional <a
href="../../HTML.html">HTML</a> attributes. If you specify a
<code>:class</code> value, it will be combined with the default class name
for your object. For example:</p>

<pre>&lt;%= content_tag_for(:li, @person, class: &quot;bar&quot;) %&gt;...</pre>

<p>produces:</p>

<pre class="ruby"><span class="ruby-operator">&lt;</span><span class="ruby-identifier">li</span> <span class="ruby-identifier">id</span>=<span class="ruby-string">&quot;person_123&quot;</span> <span class="ruby-identifier">class</span>=<span class="ruby-string">&quot;person bar&quot;</span><span class="ruby-operator">&gt;</span><span class="ruby-operator">...</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-content_tag_for_source')" id="l_method-i-content_tag_for_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/540ebe37cd1a9551b739c552a0d4efd2adc7ff22/actionpack/lib/action_view/helpers/record_tag_helper.rb#L81" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-content_tag_for_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/record_tag_helper.rb, line 81</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">content_tag_for</span>(<span class="ruby-identifier">tag_name</span>, <span class="ruby-identifier">single_or_multiple_records</span>, <span class="ruby-identifier">prefix</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">options</span> = <span class="ruby-keyword">nil</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-identifier">options</span>, <span class="ruby-identifier">prefix</span> = <span class="ruby-identifier">prefix</span>, <span class="ruby-keyword">nil</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">prefix</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)

  <span class="ruby-constant">Array</span>(<span class="ruby-identifier">single_or_multiple_records</span>).<span class="ruby-identifier">map</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">single_record</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">content_tag_for_single_record</span>(<span class="ruby-identifier">tag_name</span>, <span class="ruby-identifier">single_record</span>, <span class="ruby-identifier">prefix</span>, <span class="ruby-identifier">options</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-keyword">end</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">&quot;\n&quot;</span>).<span class="ruby-identifier">html_safe</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-div_for">
            
              <b>div_for</b>(record, *args, &amp;block)
            
            <a href="RecordTagHelper.html#method-i-div_for" name="method-i-div_for" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Produces a wrapper DIV element with id and class parameters that relate to
the specified Active Record object. Usage example:</p>

<pre>&lt;%= div_for(@person, class: &quot;foo&quot;) do %&gt;
   &lt;%= @person.name %&gt;
&lt;% end %&gt;</pre>

<p>produces:</p>

<pre class="ruby"><span class="ruby-operator">&lt;</span><span class="ruby-identifier">div</span> <span class="ruby-identifier">id</span>=<span class="ruby-string">&quot;person_123&quot;</span> <span class="ruby-identifier">class</span>=<span class="ruby-string">&quot;person foo&quot;</span><span class="ruby-operator">&gt;</span> <span class="ruby-constant">Joe</span> <span class="ruby-constant">Bloggs</span> <span class="ruby-operator">&lt;</span><span class="ruby-regexp">/div&gt;
</span></pre>

<p>You can also pass an array of Active Record objects, which will then get
iterated over and yield each record as an argument for the block. For
example:</p>

<pre>&lt;%= div_for(@people, class: &quot;foo&quot;) do |person| %&gt;
  &lt;%= person.name %&gt;
&lt;% end %&gt;</pre>

<p>produces:</p>

<pre class="ruby"><span class="ruby-operator">&lt;</span><span class="ruby-identifier">div</span> <span class="ruby-identifier">id</span>=<span class="ruby-string">&quot;person_123&quot;</span> <span class="ruby-identifier">class</span>=<span class="ruby-string">&quot;person foo&quot;</span><span class="ruby-operator">&gt;</span> <span class="ruby-constant">Joe</span> <span class="ruby-constant">Bloggs</span> <span class="ruby-operator">&lt;</span><span class="ruby-regexp">/div&gt;
&lt;div id=&quot;person_124&quot; class=&quot;person foo&quot;&gt; Jane Bloggs &lt;/</span><span class="ruby-identifier">div</span><span class="ruby-operator">&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-div_for_source')" id="l_method-i-div_for_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/540ebe37cd1a9551b739c552a0d4efd2adc7ff22/actionpack/lib/action_view/helpers/record_tag_helper.rb#L31" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-div_for_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/record_tag_helper.rb, line 31</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">div_for</span>(<span class="ruby-identifier">record</span>, *<span class="ruby-identifier">args</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-identifier">content_tag_for</span>(<span class="ruby-value">:div</span>, <span class="ruby-identifier">record</span>, *<span class="ruby-identifier">args</span>, &amp;<span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    